package cn.iocoder.yudao.module.system.controller.admin.studentdashboard.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Schema(description = "管理后台 - 学生考试对比结果 Response VO")
@Data
public class StudentExamComparisonRespVO {

    @Schema(description = "学生基本信息")
    private StudentBasicInfo studentInfo;

    @Schema(description = "考试对比数据")
    private List<ExamComparisonData> examComparisons;

    @Schema(description = "总分趋势分析")
    private TrendAnalysisInfo totalScoreTrend;

    @Schema(description = "各科趋势分析")
    private Map<String, TrendAnalysisInfo> subjectTrends;

    @Schema(description = "排名变化分析")
    private RankingTrendInfo rankingTrend;

    @Schema(description = "进步分析")
    private ProgressAnalysisInfo progressAnalysis;

    /**
     * 学生基本信息
     */
    @Data
    public static class StudentBasicInfo {
        @Schema(description = "学生ID", example = "1001")
        private Long studentId;

        @Schema(description = "学生姓名", example = "张三")
        private String studentName;

        @Schema(description = "学号", example = "G3C1001")
        private String studentNo;

        @Schema(description = "班级名称", example = "高三(1)班")
        private String className;

        @Schema(description = "年级", example = "高三")
        private String grade;
    }

    /**
     * 考试对比数据
     */
    @Data
    public static class ExamComparisonData {
        @Schema(description = "考试ID", example = "1")
        private Long examId;

        @Schema(description = "考试名称", example = "期中考试")
        private String examName;

        @Schema(description = "考试类型", example = "midterm")
        private String examType;

        @Schema(description = "考试时间", example = "2024-01-15")
        private LocalDateTime examDate;

        @Schema(description = "总分", example = "684.5")
        private BigDecimal totalScore;

        @Schema(description = "满分", example = "750.0")
        private BigDecimal fullScore;

        @Schema(description = "得分率", example = "91.3")
        private BigDecimal scoreRate;

        @Schema(description = "班级排名", example = "1")
        private Integer classRank;

        @Schema(description = "年级排名", example = "2")
        private Integer gradeRank;

        @Schema(description = "班级总人数", example = "45")
        private Integer classTotalCount;

        @Schema(description = "年级总人数", example = "200")
        private Integer gradeTotalCount;

        @Schema(description = "各科成绩")
        private Map<String, SubjectScoreInfo> subjectScores;

        @Schema(description = "与上次考试对比")
        private ComparisonWithPrevious comparisonWithPrevious;
    }

    /**
     * 科目成绩信息
     */
    @Data
    public static class SubjectScoreInfo {
        @Schema(description = "科目名称", example = "数学")
        private String subjectName;

        @Schema(description = "成绩", example = "145.0")
        private BigDecimal score;

        @Schema(description = "满分", example = "150.0")
        private BigDecimal fullScore;

        @Schema(description = "得分率", example = "96.7")
        private BigDecimal scoreRate;

        @Schema(description = "班级排名", example = "1")
        private Integer classRank;

        @Schema(description = "年级排名", example = "3")
        private Integer gradeRank;

        @Schema(description = "班级平均分", example = "128.5")
        private BigDecimal classAvgScore;

        @Schema(description = "年级平均分", example = "125.2")
        private BigDecimal gradeAvgScore;
    }

    /**
     * 与上次考试对比
     */
    @Data
    public static class ComparisonWithPrevious {
        @Schema(description = "总分变化", example = "15.5")
        private BigDecimal totalScoreChange;

        @Schema(description = "总分变化百分比", example = "2.3")
        private BigDecimal totalScoreChangePercentage;

        @Schema(description = "班级排名变化", example = "2")
        private Integer classRankChange;

        @Schema(description = "年级排名变化", example = "1")
        private Integer gradeRankChange;

        @Schema(description = "各科成绩变化")
        private Map<String, SubjectChangeInfo> subjectChanges;
    }

    /**
     * 科目变化信息
     */
    @Data
    public static class SubjectChangeInfo {
        @Schema(description = "科目名称", example = "数学")
        private String subjectName;

        @Schema(description = "分数变化", example = "7.0")
        private BigDecimal scoreChange;

        @Schema(description = "分数变化百分比", example = "5.1")
        private BigDecimal scoreChangePercentage;

        @Schema(description = "班级排名变化", example = "2")
        private Integer classRankChange;

        @Schema(description = "年级排名变化", example = "1")
        private Integer gradeRankChange;
    }

    /**
     * 趋势分析信息
     */
    @Data
    public static class TrendAnalysisInfo {
        @Schema(description = "趋势方向", example = "UP")
        private String trendDirection; // UP, DOWN, STABLE, FLUCTUATING

        @Schema(description = "趋势强度", example = "STRONG")
        private String trendStrength; // STRONG, MODERATE, WEAK

        @Schema(description = "最大值", example = "690.0")
        private BigDecimal maxValue;

        @Schema(description = "最小值", example = "650.0")
        private BigDecimal minValue;

        @Schema(description = "平均值", example = "672.5")
        private BigDecimal avgValue;

        @Schema(description = "标准差", example = "15.2")
        private BigDecimal standardDeviation;

        @Schema(description = "变化幅度", example = "40.0")
        private BigDecimal changeRange;

        @Schema(description = "连续上升次数", example = "3")
        private Integer consecutiveUpCount;

        @Schema(description = "连续下降次数", example = "0")
        private Integer consecutiveDownCount;

        @Schema(description = "波动系数", example = "0.023")
        private BigDecimal volatilityCoefficient;
    }

    /**
     * 排名趋势信息
     */
    @Data
    public static class RankingTrendInfo {
        @Schema(description = "班级排名趋势")
        private TrendAnalysisInfo classRankTrend;

        @Schema(description = "年级排名趋势")
        private TrendAnalysisInfo gradeRankTrend;

        @Schema(description = "最佳班级排名", example = "1")
        private Integer bestClassRank;

        @Schema(description = "最差班级排名", example = "3")
        private Integer worstClassRank;

        @Schema(description = "最佳年级排名", example = "1")
        private Integer bestGradeRank;

        @Schema(description = "最差年级排名", example = "5")
        private Integer worstGradeRank;

        @Schema(description = "排名稳定性", example = "HIGH")
        private String rankingStability; // HIGH, MEDIUM, LOW
    }

    /**
     * 进步分析信息
     */
    @Data
    public static class ProgressAnalysisInfo {
        @Schema(description = "总体进步情况", example = "IMPROVING")
        private String overallProgress; // IMPROVING, DECLINING, STABLE

        @Schema(description = "进步最大的科目")
        private List<SubjectProgressInfo> mostImprovedSubjects;

        @Schema(description = "需要关注的科目")
        private List<SubjectProgressInfo> needAttentionSubjects;

        @Schema(description = "总分进步幅度", example = "25.5")
        private BigDecimal totalScoreImprovement;

        @Schema(description = "排名进步幅度", example = "3")
        private Integer rankingImprovement;

        @Schema(description = "进步建议")
        private List<String> improvementSuggestions;
    }

    /**
     * 科目进步信息
     */
    @Data
    public static class SubjectProgressInfo {
        @Schema(description = "科目名称", example = "数学")
        private String subjectName;

        @Schema(description = "进步分数", example = "12.5")
        private BigDecimal progressScore;

        @Schema(description = "进步百分比", example = "9.1")
        private BigDecimal progressPercentage;

        @Schema(description = "排名进步", example = "5")
        private Integer rankingProgress;

        @Schema(description = "进步趋势", example = "CONSISTENT")
        private String progressTrend; // CONSISTENT, FLUCTUATING, RECENT

        @Schema(description = "进步评价", example = "显著进步")
        private String progressEvaluation;
    }

}
